package com.chenl.provider.DEMOS.Spring.注解的使用.ConfigurationProperties注解;

import com.alibaba.fastjson2.JSONObject;
import com.chenl.provider.DEMOS.Spring.配置白名单.WhitePropertiesByList;
import com.chenl.provider.DEMOS.设计模式.策略模式.two.AnimalService;
import com.chenl.provider.DTO.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/annoUse")
@RestController
@TestAnno
//@Import(UserInfoConfig.class) //若config配置文件不通过@Configuration 进行配置到IOC容器中,这边就必须要使用@Import导入配置 或 使用spring.factories进行配置注入
public class ConfigurationPropertiesController {
    @Autowired
    AnimalService animalService;
    @Resource(name = "setUserInfo")
    UserInfo userInfo;
    /**
     * 1.properties配置:
     * white.list:/wxLogin,/wxLogin/bindWxForLogin,...
     * 2.yml配置:
     * white:
     *   list:
     *       - sz
     *       - sz2
     */
    @Autowired
    WhitePropertiesByList whitePropertiesByList;
    /**
     * 1.properties配置:
     * yapi.config.center2Token.user-token:abc
     * yapi.config.center2Token.user2-token:szr
     * 2.yml配置:
     * yapi:
     *   config:
     *     center2Token:
     *       dcop-bs: 111
     *       message-center: 666
     *       dcop-is: 333
     */
    @Autowired
    YApiPropertiesByMap yApiPropertiesByMap;
    /**
     * anno.name: cl
     * anno.age: 23
     * anno.phone: 17720885142
     */
    @Autowired
    AnnoTestBean annoTestBean;//使用@ConfigurationProperties进行配置实体类的属性

    @GetMapping("/test")
    public String test(){
        System.out.println(whitePropertiesByList.getList());
        System.out.println(yApiPropertiesByMap.getCenter2Token());
        System.out.println(JSONObject.toJSONString( annoTestBean));
        return "ok";
    }
}
